function forEach(array, fn){
    for(let i = 0; i < array.length; i++){
        fn(array[i])
    }
}

// let arr = [1, 35, 65, 54, 8]

// forEach(arr, function(item){
//     console.log(item)
// })

function filter(array, fn){
    let results = []
    for(let i = 0; i < array.length; i++){
        if(fn(array[i])){
            results.push(array[i])
        }
    }
    return results
}

//测试
let arr = [2, 35, 6, 8, 90]
let res = filter(arr, function(item){
    return item % 2 === 0
})
console.log(res);